package com.xbongbong.paas.toolbox.util;

public class DateDiffUtil {

    private static final Long ONE_DAY_SECOND = 24 * 60 * 60L;
    private static final Long ONE_HOUR_SECOND = 60 * 60L;
    private static final Long ONE_MINUTE_SECOND = 60L;

    public static String formatInterval(Long timeInterval) {
        StringBuilder sb = new StringBuilder();
        long day = timeInterval / ONE_DAY_SECOND;
        if (day > 0) {
            String strDay = day + "天";
            sb.append(strDay);
            timeInterval = timeInterval - day * ONE_DAY_SECOND;
        }
        long hour = timeInterval / ONE_HOUR_SECOND;
        if (hour > 0) {
            String strHour = hour + "时";
            sb.append(strHour);
            timeInterval = timeInterval - hour * ONE_HOUR_SECOND;
        } else if (day > 0 && hour == 0) {
            String strHour = hour + "时";
            sb.append(strHour);
            timeInterval = timeInterval - hour * ONE_HOUR_SECOND;
        }
        long minute = timeInterval / ONE_MINUTE_SECOND;
        if (minute > 0) {
            String strMinute = minute + "分";
            sb.append(strMinute);
            timeInterval = timeInterval - minute * ONE_MINUTE_SECOND;
        } else if (hour > 0 && minute == 0) {
            String strMinute = minute + "分";
            sb.append(strMinute);
            timeInterval = timeInterval - minute * ONE_MINUTE_SECOND;
        }
        String second = timeInterval + "秒";
        sb.append(second);
        return sb.toString();
    }

}
